
#include "Chessboard.h"
#include "PieceFactory.h"
#include <iostream>
#include <string>
#include <regex>
#include <cstdio>

int main(int argc, char* argv[])
{
  std::regex rgx("^(\\d{1,2})[[:space:]](\\d{1,2})");
  Chessboard chessboard;
  Piece* piece;
  chessboard.Draw();
  std::string in;
  int turn = 0;
  printf("输入棋子坐标（x y）或（q）退出程序：\n");
  std::getline(std::cin, in);
  while (in != "q") {
    std::smatch result;
    int x, y;
    for (std::string t = in; std::regex_search(t, result, rgx); t = result.suffix()) {
      x = stoi(result[1]);
      y = stoi(result[2]);
    }
    if (++turn % 2) {
      piece = &PieceFactory::GetPiece('w');
    }
    else {
      piece = &PieceFactory::GetPiece('b');
    }
    piece->DownPiece(Point(x, y), chessboard);
    chessboard.Draw();
    printf("输入棋子坐标（x y）或（q）退出程序：\n");
    std::getline(std::cin, in);
  }
  return 0;
}
